my $wig_file=$ARGV[0];
my $chr=$ARGV[1];
my $genome_low=$ARGV[2];
my $genome_high=$ARGV[3];
my $out_file=$wig_file.".mat";
open(FH,"<$wig_file") or die;
my @in=<FH>;
chomp(@in);
close(FH);
my @out;
my $flag=0;
foreach my $line(@in){
	next if $line =~ /^track/;
	
	if($flag == 1){
		my @splitin=split "\t",$line;
			if($splitin[0] >= $genome_low and $splitin[0] >= $genome_high){
				push(@out,"$splitin[1]\n");
			}
	}
	
	if ($line =~ /chrom=(\w+)/){
		my $chr_temp= $1;
		if($chr_temp eq $chr){
			$flag=1;
			print "$chr_temp matched\n";
		}
		else{
			$flag=0;
			print "$chr_temp\n";
		}
	}
	
	
}
open(OUT,">$out_file") or die;
print OUT @out;
close(OUT);